﻿Imports Phila
Imports Phila.Sql
Imports Phila.CommonClasses

Public Class EditUser
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Not IsPostBack = True Then
                If Not IsPostBack = True Then
                    If Not Request.QueryString("id") Is Nothing Then
                        fillData(Request.QueryString("id"))
                    End If
                End If
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub fillData(ByVal Id As Integer)
        Dim arr As Array
        'arr = RetriveData("SELECT [Id] ,[Username] ,[Password] ,[Email] ,[FirstName] ,[LastName] ,[Address1] ,[Address2] ,[Address3] ,[Phone] ,[Mobile], AltEmail, Learn, Comments, Newsletter, [ViewOrder] FROM [Users] where Id=" & Id, 15)
        arr = RetriveData("SELECT [Id] ,[Username] ,[Password] ,[Email] ,[FirstName] ,[LastName] ,[Address1] ,[Address2] ,[City] ,[Country] ,[Phone] ,[Mobile] ,[AltEmail] ,[Learn] ,[Comments] ,[Newsletter] ,[IsAdmin] ,[ViewOrder] ,[IsActive] ,[CreatedOn], [IsB2B] FROM [ptn_Users] where Id=" & Id, 20)

        txtEmail.Text = arr(3)
        txtFName.Text = arr(4)
        txtLName.Text = arr(5)
        txtAdd1.Text = arr(6)
        txtAdd2.Text = arr(7)
        txtCity.Text = arr(8)
        cmbCountry.SelectedItem.Text = arr(9)
        txtPhone.Text = arr(10)
        txtMobile.Text = arr(11)
        txtAltEmail.Text = arr(12)
        cmbLearn.SelectedValue = arr(13)
        txtComments.Text = arr(14)
        chkNewL.Checked = arr(15)
        chkActive.Checked = arr(18)
        txtDate.Text = DisplayDate(arr(19))
        chkb2b.Checked = arr(20)
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Dim strActive, strB2B, strNewsL As String
            Dim strBody As New StringBuilder
            If chkActive.Checked = True Then
                strActive = "1"
            Else
                strActive = "0"
            End If
            If chkb2b.Checked = True Then
                strB2B = "1"
            Else
                strB2B = "0"
            End If
            If chkNewL.Checked = True Then
                strNewsL = "1"
            Else
                strNewsL = "0"
            End If

            If Not Request.QueryString("id") Is Nothing Then
                'If strActive = 0 Then
                Insert_Update_Delete_Record("UPDATE ptn_Users Set IsActive='" & strActive & "', IsB2B='" & strB2B & "',Newsletter='" & strNewsL & "' where Id=" & Request.QueryString("id"))
                strBody.Append("<p style=""font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333333"">Dear " & txtFName.Text & ",<br> <br>")
                strBody.Append("Thank you for registering with Philatourism. Your Philatourism Account has been activated. <br><br>")
                strBody.Append("Now you can start booking your tours and hotels with us.<br><br>")
                strBody.Append("If you have any enquiry for customized packages<br><br />")
                strBody.Append("With best regards,<br> Phila Tours & Travels Pvt. Ltd.<br>")
                strBody.Append("<a href=""http://www.philatourism.com"" target=""_new"" style=""color:#db261f"">http://www.philatourism.com</a><br>")

                'If SendmailAuth("info@philatourism.com", txtEmail.Text, "Your Philatourism Account has been activated", strBody.ToString, "", False, "info@philatourism.com," & txtEmail.Text & "", True) = True Then
                If Sendmail("info@philatourism.com", txtEmail.Text, "Your Philatourism Account has been activated", strBody.ToString, "info@philatourism.com", True) = True Then
                    Response.Redirect("ViewUsers.aspx")
                Else
                    lblMsg.Text = "Error has occured."
                    lblMsg.ForeColor = Drawing.Color.Red
                    lblMsg.Visible = True
                End If
                'End If
            End If

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("ViewUsers.aspx")
    End Sub

    Protected Sub cmdPassword_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPassword.Click
        Try
            Dim strBody As New StringBuilder
            Dim txt As Array
            txt = RetriveData("select Email, Password from Users where email='" & txtEmail.Text & "'", 1)
            strBody.Append("<p style=""font-family:Arial, Helvetica, sans-serif; font-size:12px"">Hi Info,<br><br>")
            strBody.Append("Password for <a href=""mailto:" & txt(0) & """>" & txt(0) & "</a> has been reset.<br><br>")
            strBody.Append("Here's all the information you need to get you started -<br><br>")
            strBody.Append("------------------<br>Login Information:<br>------------------<br>")
            strBody.Append("User ID: <a href=""mailto:" & txt(0) & """>" & txt(0) & "</a><br>")
            strBody.Append("Password: " & txt(1) & "</p>")

            strBody.Append("With best regards,<br> Phila Tours & Travels Pvt. Ltd.<br>")
            strBody.Append("<a href=""http://www.philatourism.com"" target=""_new"" style=""color:#db261f"">http://www.philatourism.com</a><br>")
            strBody.Append("<a href=""http://b2b.philatourism.com"" target=""_new"" style=""color:#db261f"">http://b2b.philatourism.com</a></p>")

            'If SendmailAuth("enquiry@philatourism.com", txt(0), "Password reset for " & txt(0), strBody.ToString, "", False, "enquiry@philatourism.com", True) = True Then
            If SendmailAuth("enquiry@philatourism.com", txt(0), "Password reset for " & txt(0), strBody.ToString, "enquiry@philatourism.com", True) = True Then
                lblMsg.Text = "<h3>Password has been reset successfully for " & txt(0) & "</h3>"
                lblMsg.ForeColor = Drawing.Color.Green
            Else
                lblMsg.Text = "<h3>Error has occured. Password has not been reset </h3>"
                lblMsg.ForeColor = Drawing.Color.Red
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

End Class